﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using WatiNCF.Automater.Business;
using WatiNCF.Automater.Business.Adapters;

namespace WatiNCF.Automater.Controls
{
    public static class DataEntryControlFactory
    {
        public static ParameterInputForm GetInputForm(AutomationMethod autoMethod)
        {
            return new ParameterInputForm()
            {
                Target = autoMethod.Target,
                Method = autoMethod.Method
            };
        }

        public static BaseDataEntryControl GetControl(ParameterInfo info)
        {
            return GetControl(new ParameterInfoAdapter(info));
        }

        public static BaseDataEntryControl GetControl(object target, PropertyInfo info)
        {
            return GetControl(new PropertyInfoAdapter(target, info));
        }

        public static BaseDataEntryControl GetControl(InfoAdapter adapter)
        {
            BaseDataEntryControl control = null;
            Type infoType = adapter.GetInfoType();
            if (infoType.IsEnum)
            {
                control = new EnumEntryControl();
            }
            else if (infoType.IsValueType)
            {
                control = new StringEntryControl();
            }
            else
            {
                switch (infoType.Name)
                {
                    case "String":
                    case "String&":
                        {
                            control = new StringEntryControl();
                            break;
                        }
                    case "DateTime":
                        {
                            control = new DateEntryControl();
                            break;
                        }
                    default:
                        {
                            control = new ObjectEntryControl();
                            break;
                        }
                }
            }
            control.Adapter = adapter;

            return control;
        }
    }
}
